//
//  GZLoadingView.m
//  GongZheng
//
//  Created by huan on 2018/4/27.
//  Copyright © 2018年 huan. All rights reserved.
//

#import "GZLoadingView.h"

@implementation GZLoadingView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self creatAnimation];
    }
    return self;
}

/**
 用uiview自定义MBHUD的customview必须使用此方法设置下大小
 */
- (CGSize)intrinsicContentSize {
    return CGSizeMake(self.width, self.height);
}

- (void)creatAnimation {
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.bounds          = self.bounds;
    //    replicatorLayer.cornerRadius    = 10.0;
    replicatorLayer.position        = self.center;
    //    replicatorLayer.backgroundColor = [UIColor redColor].CGColor;//[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.2].CGColor;
    [self.layer addSublayer:replicatorLayer];
    
    CALayer *dot        = [CALayer layer];
    dot.bounds          = CGRectMake(0, 0, 10, 10);
    dot.position        = CGPointMake(50, 10); // 动此处是改变了第一个转点的位置
    dot.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.6].CGColor;
    dot.cornerRadius    = 5;
    dot.masksToBounds   = YES;
    [replicatorLayer addSublayer:dot];
    
    CGFloat count                     = 9.0;
    replicatorLayer.instanceCount     = count;
    CGFloat angel                     = 2* M_PI/count;
    replicatorLayer.instanceTransform = CATransform3DMakeRotation(angel, 0, 0, 1);
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.duration    = 1.0;
    animation.fromValue   = @1;
    animation.toValue     = @0.1;
    animation.repeatCount = MAXFLOAT;
    [dot addAnimation:animation forKey:nil];
    
    replicatorLayer.instanceDelay = 1.0 / count;
    dot.transform = CATransform3DMakeScale(0.01, 0.01, 0.01);
}
@end
